home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / Devcon_Extras / Example_Code / JoyportOutput / SetPot.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.3 KB  |  98 lines

  1. /*
  2.  * SetPot.c   C. Scheppner  CBM  01/89
  3.  * Sets right joyport PotX and PotY pins (pins 5 and 9) to 0 and 1
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <libraries/dos.h>
  8. #include <resources/potgo.h>
  9.  
  10.  
  11. #define V1_POINT_2   33
  12.  
  13. /* potgo bits */
  14. #define START_B      0   
  15. #define START_F      (1L << START_B)
  16. #define OUTRY_B      15
  17. #define OUTRY_F      (1L << OUTRY_B)
  18. #define DATRY_B      14
  19. #define DATRY_F      (1L << DATRY_B)
  20. #define OUTRX_B      13
  21. #define OUTRX_F      (1L << OUTRX_B)
  22. #define DATRX_B      12
  23. #define DATRX_F      (1L << DATRX_B)
  24.  
  25. /* We want the right port PotX and PotY direction and data bits */
  26. #define OURBITS    (OUTRY_F|DATRY_F|OUTRX_F|DATRX_F)
  27.  
  28. /* Mask and bit combinations for setting and clearing the X and Y pots 
  29.  * For mask,  affect both the direction and data bits  
  30.  * For data,  CLR = (direction out,data 0)    SET = (direction out,data 1)
  31.  */
  32. #define POTRX_MSK  (OUTRX_F|DATRX_F)
  33. #define POTRX_CLR  (OUTRX_F)
  34. #define POTRX_SET  (OUTRX_F|DATRX_F)
  35.  
  36. #define POTRY_MSK  (OUTRY_F|DATRY_F)
  37. #define POTRY_CLR  (OUTRY_F)
  38. #define POTRY_SET  (OUTRY_F|DATRY_F)
  39.  
  40. struct PotgoBase *PotgoBase = NULL;
  41.  
  42. UWORD  ourpotbits = NULL; 
  43.  
  44. main(argc,argv)
  45. int argc;
  46. char **argv;
  47.    {
  48.    ULONG delay = 500;
  49.  
  50.    if(argc > 1)
  51.       {
  52.       if(argv[1][0]=='?')
  53.          cleanexit("USAGE: SetPot  (demos setting of right joyport potx/y)\n");
  54.       }
  55.  
  56.    if(!(PotgoBase=
  57.      (struct PotgoBase *)OpenResource(POTGONAME,V1_POINT_2)))
  58.        cleanexit("Can't open potgo\n",RETURN_FAIL);
  59.  
  60.    ourpotbits = AllocPotBits(OURBITS);
  61.    if(ourpotbits != OURBITS)   cleanexit("Can't alloc potbits\n,RETURN_FAIL");
  62.  
  63.    /* We got our bits... Loop until done */
  64.    printf("SetPot sets the right port POTX and POTY pins (5,9) to 0 and 1\n");
  65.    printf("Use CTRL/C to exit...\n");
  66.    while(!(SetSignal(0,0) & SIGBREAKF_CTRL_C))
  67.       {
  68.       /* We are setting both pots, so we use both X and Y, masks and data */
  69.       printf("\nSetting right Potx and Poty to 0...  ");
  70.       WritePotgo(POTRX_CLR|POTRY_CLR, POTRX_MSK|POTRY_MSK);
  71.       Delay(delay);
  72.  
  73.       printf("Setting right Potx and Poty to 1...  ");
  74.       WritePotgo(POTRX_SET|POTRY_SET, POTRX_MSK|POTRY_MSK);
  75.       Delay(delay);
  76.       }
  77.  
  78.    printf("\n");
  79.    cleanup();
  80.    exit(0);
  81.    }
  82.  
  83. cleanexit(s,n)
  84. char *s;
  85. int n;
  86.    {
  87.    if(*s)  printf(s);
  88.    cleanup();
  89.    exit(n);
  90.    }
  91.  
  92. cleanup()
  93.    {
  94.    if(ourpotbits)   FreePotBits(ourpotbits);
  95.    }
  96.  
  97. /* end */
  98.